package paper;

public class Username {
    private String reg = "[a-zA-Z]";
    private String regx = "[a-zA-Z0-9_]";
    private String username;
    private String tip;
    private boolean isval;

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getTip() {
        return tip;
    }

    public void setTip(String tip) {
        this.tip = tip;
    }

    public boolean isIsval() {
        return isval;
    }

    public void setIsval(boolean isval) {
        this.isval = isval;
    }
    public boolean isValid() {
        String name = this.getUsername();
        String firstname = String.valueOf(name.charAt(0));
        //判断首个是否符合
        if (firstname.matches(reg)) {
            //首个符合，判断后续是否符合
            for (int i = 1;i < name.length();i++) {
                if (!String.valueOf(name.charAt(i)).matches(regx)) {
                    setTip("必须为数字、字母、下划线!");
                    return false;
                }
            }
            setTip("格式正确!");
            return true;
        } else {
            setTip("首字母只能为大写或小写字母!");
            return false;
        }
    }
}
